package com.cellngine.hub;

import java.util.Enumeration;
import java.util.Hashtable;

public class MIME
{
	private static Hashtable<String, String>	mime_types;
	
	static
	{
		mime_types = new Hashtable<String, String>();
		
		mime_types.put("html|htm", "text/html; charset=UTF-8");
		mime_types.put("css", "text/css; charset=UTF-8");
		
		mime_types.put("gif", "image/gif");
		mime_types.put("png", "image/png");
		mime_types.put("jpg|jpeg", "image/jpeg");
	}
	
	public static String getContentType(String path)
	{
		path = path.substring(path.lastIndexOf("."));
		
		final Enumeration<String> exts = mime_types.keys();
		String ext;
		while (exts.hasMoreElements())
		{
			ext = exts.nextElement();
			
			if (path.matches("\\.(" + ext + ")"))
			{
				return mime_types.get(ext);
			}
		}
		
		return "text/plain; charset=UTF-8";
	}
}